//
//  NSString+NSString_ext.m
//  Keyboard
//
//  Created by tucici on 2023/3/8.
//

#import "NSString+exx.h"

@implementation NSString (NSString_ext)
- (NSString *) utf8ToUnicode{
    NSUInteger length = [self length];
    NSMutableString *str = [NSMutableString stringWithCapacity:0];
    for (int i = 0;i < length; i++){
        NSMutableString *s = [NSMutableString stringWithCapacity:0];
        unichar _char = [self characterAtIndex:i];
        // 中文和字符
        [s appendFormat:@"\\u%x",[self characterAtIndex:i]];
        // 不足位数补0 否则解码不成功
        if (s.length == 4) {
            [s insertString:@"00" atIndex:2];
        } else if (s.length == 5) {
            [s insertString:@"0" atIndex:2];
        }
        [str appendFormat:@"%@", s];
    }
    return str;
}
@end
